package com.race;

import java.util.HashMap;
import java.util.Map;

public class Main {

    public static void main(String[] args) {
        String s1 = "we\nare\ndict\nare\ne";
        String s2 = "we he\nare is\n";

        String[] strings = s2.split("\\n");
        Map<String, String> dic = new HashMap<>();

        String[] tmp;
        for (String str : strings) {
            tmp = str.split(" ");
            if (tmp.length == 2) {
                dic.put(tmp[0], tmp[1]);
            }
        }

        strings = s1.split("\\n");

        String word;
        String result = "";
        System.out.print("result = ");
        for (int i = 0; i < strings.length; i++) {
            word = dic.get(strings[i]);
            if (null != word) {
                strings[i] = word;
            }

            result += strings[i] + " ";
        }

        System.out.println(result);
    }

}
